﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using FlyCode.DBUtility;//Please add references
namespace com.DAL.laibendi
{
    /// <summary>
    /// 数据访问类:T_Seller
    /// </summary>
    public class T_Seller
    {
        public T_Seller()
        { }
        #region  Method

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long SellerId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Seller");
            strSql.Append(" where SellerId=@SellerId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SellerId", SqlDbType.BigInt)};
            parameters[0].Value = SellerId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(com.Model.laibendi.T_Seller model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Seller(");
            strSql.Append("MemberId,SellerName,SellerType,Address,Province,City,Area,Telephone,BusinessTime,BusinessArea,AvgComsumption,IsSupportCard,DiscountCard,Grade,HasPart,BusStop,BusLine,Intro,feature,logo,DiscountContent)");
            strSql.Append(" values (");
            strSql.Append("@MemberId,@SellerName,@SellerType,@Address,@Province,@City,@Area,@Telephone,@BusinessTime,@BusinessArea,@AvgComsumption,@IsSupportCard,@DiscountCard,@Grade,@HasPart,@BusStop,@BusLine,@Intro,@feature,@logo,@DiscountContent)");
            SqlParameter[] parameters = {					
					new SqlParameter("@MemberId", SqlDbType.BigInt,8),
					new SqlParameter("@SellerName", SqlDbType.NVarChar,50),
					new SqlParameter("@SellerType", SqlDbType.Int,4),
					new SqlParameter("@Address", SqlDbType.NVarChar,50),
					new SqlParameter("@Province", SqlDbType.NVarChar,50),
					new SqlParameter("@City", SqlDbType.NVarChar,50),
					new SqlParameter("@Area", SqlDbType.NVarChar,50),
					new SqlParameter("@Telephone", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessTime", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessArea", SqlDbType.NVarChar,50),
					new SqlParameter("@AvgComsumption", SqlDbType.Int,4),
					new SqlParameter("@IsSupportCard", SqlDbType.Char,10),
					new SqlParameter("@DiscountCard", SqlDbType.NVarChar,50),
					new SqlParameter("@Grade", SqlDbType.Float,8),
					new SqlParameter("@HasPart", SqlDbType.Char,10),
					new SqlParameter("@BusStop", SqlDbType.NVarChar,50),
					new SqlParameter("@BusLine", SqlDbType.NVarChar,50),
					new SqlParameter("@Intro", SqlDbType.Text),
					new SqlParameter("@feature", SqlDbType.Text),
					new SqlParameter("@logo", SqlDbType.NVarChar,50),
					new SqlParameter("@DiscountContent", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.MemberId;
            parameters[1].Value = model.SellerName;
            parameters[2].Value = model.SellerType;
            parameters[3].Value = model.Address;
            parameters[4].Value = model.Province;
            parameters[5].Value = model.City;
            parameters[6].Value = model.Area;
            parameters[7].Value = model.Telephone;
            parameters[8].Value = model.BusinessTime;
            parameters[9].Value = model.BusinessArea;
            parameters[10].Value = model.AvgComsumption;
            parameters[11].Value = model.IsSupportCard;
            parameters[12].Value = model.DiscountCard;
            parameters[13].Value = model.Grade;
            parameters[14].Value = model.HasPart;
            parameters[15].Value = model.BusStop;
            parameters[16].Value = model.BusLine;
            parameters[17].Value = model.Intro;
            parameters[18].Value = model.feature;
            parameters[19].Value = model.logo;
            parameters[20].Value = model.DiscountContent;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(com.Model.laibendi.T_Seller model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Seller set ");
            strSql.Append("MemberId=@MemberId,");
            strSql.Append("SellerName=@SellerName,");
            strSql.Append("SellerType=@SellerType,");
            strSql.Append("Address=@Address,");
            strSql.Append("Province=@Province,");
            strSql.Append("City=@City,");
            strSql.Append("Area=@Area,");
            strSql.Append("Telephone=@Telephone,");
            strSql.Append("BusinessTime=@BusinessTime,");
            strSql.Append("BusinessArea=@BusinessArea,");
            strSql.Append("AvgComsumption=@AvgComsumption,");
            strSql.Append("IsSupportCard=@IsSupportCard,");
            strSql.Append("DiscountCard=@DiscountCard,");
            strSql.Append("Grade=@Grade,");
            strSql.Append("HasPart=@HasPart,");
            strSql.Append("BusStop=@BusStop,");
            strSql.Append("BusLine=@BusLine,");
            strSql.Append("Intro=@Intro,");
            strSql.Append("feature=@feature,");
            strSql.Append("logo=@logo,");
            strSql.Append("DiscountContent=@DiscountContent");
            strSql.Append(" where SellerId=@SellerId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SellerId", SqlDbType.BigInt,8),
					new SqlParameter("@MemberId", SqlDbType.BigInt,8),
					new SqlParameter("@SellerName", SqlDbType.NVarChar,50),
					new SqlParameter("@SellerType", SqlDbType.Int,4),
					new SqlParameter("@Address", SqlDbType.NVarChar,50),
					new SqlParameter("@Province", SqlDbType.NVarChar,50),
					new SqlParameter("@City", SqlDbType.NVarChar,50),
					new SqlParameter("@Area", SqlDbType.NVarChar,50),
					new SqlParameter("@Telephone", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessTime", SqlDbType.NVarChar,50),
					new SqlParameter("@BusinessArea", SqlDbType.NVarChar,50),
					new SqlParameter("@AvgComsumption", SqlDbType.Int,4),
					new SqlParameter("@IsSupportCard", SqlDbType.Char,10),
					new SqlParameter("@DiscountCard", SqlDbType.NVarChar,50),
					new SqlParameter("@Grade", SqlDbType.Float,8),
					new SqlParameter("@HasPart", SqlDbType.Char,10),
					new SqlParameter("@BusStop", SqlDbType.NVarChar,50),
					new SqlParameter("@BusLine", SqlDbType.NVarChar,50),
					new SqlParameter("@Intro", SqlDbType.Text),
					new SqlParameter("@feature", SqlDbType.Text),
					new SqlParameter("@logo", SqlDbType.NVarChar,50),
					new SqlParameter("@DiscountContent", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.SellerId;
            parameters[1].Value = model.MemberId;
            parameters[2].Value = model.SellerName;
            parameters[3].Value = model.SellerType;
            parameters[4].Value = model.Address;
            parameters[5].Value = model.Province;
            parameters[6].Value = model.City;
            parameters[7].Value = model.Area;
            parameters[8].Value = model.Telephone;
            parameters[9].Value = model.BusinessTime;
            parameters[10].Value = model.BusinessArea;
            parameters[11].Value = model.AvgComsumption;
            parameters[12].Value = model.IsSupportCard;
            parameters[13].Value = model.DiscountCard;
            parameters[14].Value = model.Grade;
            parameters[15].Value = model.HasPart;
            parameters[16].Value = model.BusStop;
            parameters[17].Value = model.BusLine;
            parameters[18].Value = model.Intro;
            parameters[19].Value = model.feature;
            parameters[20].Value = model.logo;
            parameters[21].Value = model.DiscountContent;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long SellerId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Seller ");
            strSql.Append(" where SellerId=@SellerId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SellerId", SqlDbType.BigInt)};
            parameters[0].Value = SellerId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string SellerIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Seller ");
            strSql.Append(" where SellerId in (" + SellerIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public com.Model.laibendi.T_Seller GetModel(long SellerId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 SellerId,MemberId,SellerName,SellerType,Address,Province,City,Area,Telephone,BusinessTime,BusinessArea,AvgComsumption,IsSupportCard,DiscountCard,Grade,HasPart,BusStop,BusLine,Intro,feature,logo,DiscountContent from T_Seller ");
            strSql.Append(" where SellerId=@SellerId ");
            SqlParameter[] parameters = {
					new SqlParameter("@SellerId", SqlDbType.BigInt)};
            parameters[0].Value = SellerId;

            com.Model.laibendi.T_Seller model = new com.Model.laibendi.T_Seller();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["SellerId"].ToString() != "")
                {
                    model.SellerId = long.Parse(ds.Tables[0].Rows[0]["SellerId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MemberId"].ToString() != "")
                {
                    model.MemberId = long.Parse(ds.Tables[0].Rows[0]["MemberId"].ToString());
                }
                model.SellerName = ds.Tables[0].Rows[0]["SellerName"].ToString();
                if (ds.Tables[0].Rows[0]["SellerType"].ToString() != "")
                {
                    model.SellerType = int.Parse(ds.Tables[0].Rows[0]["SellerType"].ToString());
                }
                model.Address = ds.Tables[0].Rows[0]["Address"].ToString();
                model.Province = ds.Tables[0].Rows[0]["Province"].ToString();
                model.City = ds.Tables[0].Rows[0]["City"].ToString();
                model.Area = ds.Tables[0].Rows[0]["Area"].ToString();
                model.Telephone = ds.Tables[0].Rows[0]["Telephone"].ToString();
                model.BusinessTime = ds.Tables[0].Rows[0]["BusinessTime"].ToString();
                model.BusinessArea = ds.Tables[0].Rows[0]["BusinessArea"].ToString();
                if (ds.Tables[0].Rows[0]["AvgComsumption"].ToString() != "")
                {
                    model.AvgComsumption = int.Parse(ds.Tables[0].Rows[0]["AvgComsumption"].ToString());
                }
                model.IsSupportCard = ds.Tables[0].Rows[0]["IsSupportCard"].ToString();
                model.DiscountCard = ds.Tables[0].Rows[0]["DiscountCard"].ToString();
                if (ds.Tables[0].Rows[0]["Grade"].ToString() != "")
                {
                    model.Grade = decimal.Parse(ds.Tables[0].Rows[0]["Grade"].ToString());
                }
                model.HasPart = ds.Tables[0].Rows[0]["HasPart"].ToString();
                model.BusStop = ds.Tables[0].Rows[0]["BusStop"].ToString();
                model.BusLine = ds.Tables[0].Rows[0]["BusLine"].ToString();
                model.Intro = ds.Tables[0].Rows[0]["Intro"].ToString();
                model.feature = ds.Tables[0].Rows[0]["feature"].ToString();
                model.logo = ds.Tables[0].Rows[0]["logo"].ToString();
                model.DiscountContent = ds.Tables[0].Rows[0]["DiscountContent"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SellerId,MemberId,SellerName,SellerType,Address,Province,City,Area,Telephone,BusinessTime,BusinessArea,AvgComsumption,IsSupportCard,DiscountCard,Grade,HasPart,BusStop,BusLine,Intro,feature,logo,DiscountContent ");
            strSql.Append(" FROM T_Seller ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetSellerNameList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select SellerId,MemberId,SellerName ");
            strSql.Append(" FROM T_Seller ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }


        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" SellerId,MemberId,SellerName,SellerType,Address,Province,City,Area,Telephone,BusinessTime,BusinessArea,AvgComsumption,IsSupportCard,DiscountCard,Grade,HasPart,BusStop,BusLine,Intro,feature,logo,DiscountContent ");
            strSql.Append(" FROM T_Seller ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "T_Seller";
            parameters[1].Value = "SellerId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  Method
    }
}

